package com.youdianstar.app.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.youdianstar.app.common.util.DateUtil
import com.youdianstar.app.common.util.MathUtil
import com.youdianstar.app.R
import com.youdianstar.app.databinding.LayoutItemInviteRecordBinding
import com.youdianstar.app.entity.InviteRc
import com.youdianstar.app.util.DataAppManager


/**
 * File: InviteRecordAdapter
 * Author: 82149 Create: 2023/8/5 16:57
 * Changes (from 2023/8/5)
 * --------------------------------------------------
 * description: 分享-邀请记录
 * ---------------------------------------------------
 *
 */
class InviteRecordAdapter(val mContext: Context, val dataList: List<InviteRc>) : RecyclerView.Adapter<InviteRecordAdapter.ListHolder>() {
    class ListHolder(val binding : LayoutItemInviteRecordBinding) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListHolder {
        return ListHolder(LayoutItemInviteRecordBinding.inflate(LayoutInflater.from(parent.context), parent, false))
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    override fun onBindViewHolder(holder: ListHolder, position: Int) {
        dataList[position].let { item ->
            holder.binding.itemTitle.text = mContext.getString(R.string.points_inviteFried)
            holder.binding.itemDate.text = DateUtil.getOrderTime(item.createTime)

            val symbolStr = DataAppManager.instance.symbolTx()
            //奖励类型：1-积分 2-优惠券 3-余额
            when(item.type){
                1->{
                    holder.binding.itemPoints.text = "+" + item.point.toString()
                }
                2->{
                    holder.binding.itemPoints.text = mContext.getString(R.string.invite_coupon)
                }
                3->{
                    holder.binding.itemPoints.text = "+" +symbolStr+ MathUtil.round(item.amount)
                }
                else ->{
                    holder.binding.itemPoints.text = "--"
                }
            }
        }
    }
}